package com.zisu.wcsopcua.opcua.Consumer;

import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2021/8/18 14:32
 */
@Component
public class EventReceivedCallBack implements UaMonitoredItem.EventConsumer,UaMonitoredItem.ValueConsumer {
    private static final Logger logger = LoggerFactory.getLogger(EventReceivedCallBack.class);


    @Override
    public void onEventArrived(UaMonitoredItem uaMonitoredItem, Variant[] variants) {
        logger.info("Server Event Received from {}", uaMonitoredItem.getReadValueId().getNodeId());
        //这里variants 就是 0,2253 这个事件的 变量
        for (int i = 0; i < variants.length; i++) {
            logger.info("\t variant[{}]: {}", i, variants[i].getValue());
        }
    }

    @Override
    public void onValueArrived(UaMonitoredItem item, DataValue dataValue) {

    }
}
